package com.beyond.trace.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.beyond.trace.domain.TraceConsumable;
import com.beyond.trace.service.ITraceConsumableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消耗品信息Controller
 * 
 * @author yao
 * @date 2022-03-02
 */
@RestController
@RequestMapping("/trace/consumable")
@Api(value = "消耗品信息", tags = "消耗品信息")
public class TraceConsumableController extends BaseController
{
    @Autowired
    private ITraceConsumableService traceConsumableService;

    //@PreAuthorize("@ss.hasPermi('beyond:consumable:list')")
    @GetMapping("/list")
    @ApiOperation("查询消耗品信息列表")
    public TableDataInfo list(TraceConsumable traceConsumable)
    {
        startPage();
        List<TraceConsumable> list = traceConsumableService.selectTraceConsumableList(traceConsumable);
        return getDataTable(list);
    }

    //@PreAuthorize("@ss.hasPermi('beyond:consumable:query')")
    @GetMapping(value = "/query")
    @ApiOperation("查询消耗品信息列表不分页")
    public AjaxResult getInfoQuery(TraceConsumable traceConsumable)
    {
        return AjaxResult.success(traceConsumableService.selectTraceConsumableList(traceConsumable));
    }

    //@PreAuthorize("@ss.hasPermi('beyond:consumable:export')")
    @Log(title = "消耗品信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TraceConsumable traceConsumable)
    {
        List<TraceConsumable> list = traceConsumableService.selectTraceConsumableList(traceConsumable);
        ExcelUtil<TraceConsumable> util = new ExcelUtil<TraceConsumable>(TraceConsumable.class);
        return util.exportExcel(list, "消耗品信息数据");
    }

    //@PreAuthorize("@ss.hasPermi('beyond:consumable:query')")
    @GetMapping(value = "/{consumableId}")
    @ApiOperation("查询消耗品信息列表")
    public AjaxResult getInfo(@PathVariable("consumableId") Long consumableId)
    {
        return AjaxResult.success(traceConsumableService.selectTraceConsumableById(consumableId));
    }

    //@PreAuthorize("@ss.hasPermi('beyond:consumable:add')")
    @Log(title = "消耗品信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增消耗品信息")
    public AjaxResult add(@RequestBody @Validated TraceConsumable traceConsumable)
    {
        return toAjax(traceConsumableService.insertTraceConsumable(traceConsumable));
    }

    //@PreAuthorize("@ss.hasPermi('beyond:consumable:edit')")
    @Log(title = "消耗品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改消耗品信息")
    public AjaxResult edit(@RequestBody TraceConsumable traceConsumable)
    {
        return toAjax(traceConsumableService.updateTraceConsumable(traceConsumable));
    }

    //@PreAuthorize("@ss.hasPermi('beyond:consumable:remove')")
    @Log(title = "消耗品信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{consumableIds}")
    @ApiOperation("删除消耗品信息")
    public AjaxResult remove(@PathVariable Long[] consumableIds)
    {
        return toAjax(traceConsumableService.deleteTraceConsumableByIds(consumableIds));
    }
}
